package com.lixixi.tingshu.order.handler;

import com.lixixi.tingshu.common.result.ResultCodeEnum;
import com.lixixi.tingshu.exception.BaseException;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

@Component
public class ProducerResultHandler implements ProducerListener {
	@Override
	public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
		ProducerListener.super.onSuccess(producerRecord, recordMetadata);
	}

	@Override
	public void onError(ProducerRecord producerRecord, RecordMetadata recordMetadata, Exception exception) throws BaseException{
		ProducerListener.super.onError(producerRecord, recordMetadata, exception);
		throw new BaseException(ResultCodeEnum.ORDER_SAVE_ERROR);
	}
}
